﻿Public Class FrmPropDownQuery

    Private Sub ButtonX1_Click(sender As Object, e As EventArgs) Handles ButtonX1.Click
        Try
            Dim FType As String = "CN"
            If CheckBox1.Checked Then
                FType = "ZF"
            Else
                FType = ""
            End If
            If CheckBox2.Checked Then
                FType = "*" & FType
            Else
                FType = "CN" & FType
            End If
            Dim ds As New DataSet
            Dim ErrString As String = Nothing
            Dim TmpArr As Byte() = Nothing
            If SControl._BILL_PropertyDown_QueryBill(UInfo.FSession, FType, UInfo.FOrgid, DateTimePicker1.Value.ToString("yyyy-MM-dd"), DateTimePicker2.Value.ToString("yyyy-MM-dd"), "", TmpArr, ErrString) = False Then
                MsgBox(ErrString)
                Return
            End If
            If FControl.DsRestore(ds, TmpArr) = False Then
                MsgBox("无法解析返回数据!")
                Return
            End If
            DataGridView1.DataSource = ds.Tables(0).DefaultView
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub DataGridView1_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
        If DataGridView1.SelectedCells.Count < 1 Then
            Return
        End If
        Try
            Dim sid As Integer = DataGridView1.Item(0, e.RowIndex).Value
            If sid <= 0 Then
                Return
            End If
            Dim f1 As New FrmPropDownBill With {.FBid = sid, .FOpenType = "View"}
            f1.ShowDialog()
            f1 = Nothing
        Catch ex As Exception

        End Try
    End Sub

    Private Sub ButtonX4_Click(sender As Object, e As EventArgs) Handles ButtonX4.Click
        Try
            If DataGridView1.SelectedCells.Count < 1 Then
                MsgBox("必须选择一个要作废的单据!")
                Return
            End If
            Dim sid As Integer = DataGridView1.Item(0, DataGridView1.SelectedCells(0).RowIndex).Value
            If sid <= 0 Then
                Return
            End If
            Dim ErrString As String = Nothing
            If SControl._BILL_PropertyDown_Cancel(UInfo.FSession, sid, ErrString) = False Then
                MsgBox(ErrString)
                Return
            End If
            MsgBox("作废成功!")

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub ButtonX2_Click(sender As Object, e As EventArgs) Handles ButtonX2.Click
        FControl.ExpertToXls(DataGridView1)
    End Sub
End Class